package com.cs.controller;

import com.github.pagehelper.PageInfo;
import com.cs.pojo.Hosregister;
import com.cs.service.HosRegisterService;
import com.cs.resultVO.HosRegisterQueryVO;
import com.cs.resultVO.ResultVO;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

@Controller
@RequestMapping("hosRegister")
@ResponseBody
public class HosRegisterController {

    @Resource
    HosRegisterService hosRegisterService;

    //如果实体类中的日期类型需要从页面中获取数据，避免NULL转换为Date出现错误
    @InitBinder
    protected void initDateFormatBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        binder.registerCustomEditor(Date.class,new CustomDateEditor(dateFormat,true));
    }

    //多条件分页查询
    @RequestMapping(value = "list.do",method = RequestMethod.GET)
    public ResultVO<Hosregister> queryByPage(Integer pageNum, Integer pageSize, HosRegisterQueryVO hosRegisterQueryVO) {
        if (pageNum == null || pageNum <= 0) {
            pageNum = 1;
        }
        if (pageSize == null || pageSize <= 0) {
            pageSize = 5;
        }
        PageInfo<Hosregister> hosregisterPageInfo = hosRegisterService.queryByPage(pageNum, pageSize, hosRegisterQueryVO);
        return new ResultVO<>(hosregisterPageInfo);
    }

}
